/**
 * Created by yuanchao on 2017/9/17.
 * 解析URL参数
 * @example ?id=12345&a=b
 * @return Object {id: 12345, a:b}
 */
export function urlParse () {
  // ?id=12345&a=b
  let url = window.location.search;
  let obj = {};
  let reg = /[?&][^?&]+=[^?&]+/g;   // ^表示非, [^?&]+表示多个非?和&的字符
  let arr = url.match(reg);
  // ['?id=12345','&a=b']
  if (arr) {
    arr.forEach((item) => {
      // ['id','12345']
      let tempArr = item.substring(1).split('=');
      let key = decodeURIComponent(tempArr[0]);
      let val = decodeURIComponent(tempArr[1]);
      obj[key] = val;
    });
  }
  return obj;
}
